package com.doctor.database;

import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;


public class DES {
	    public static String KEY="80576241";
        private static byte[] iv = {8,0,5,7,6,2,4,1};
        public static String encryptDES(String encryptString, String encryptKey) throws Exception {
//                IvParameterSpec zeroIv = new IvParameterSpec(new byte[8]);
                IvParameterSpec zeroIv = new IvParameterSpec(iv);
                SecretKeySpec key = new SecretKeySpec(encryptKey.getBytes(), "DES");
                Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
                cipher.init(Cipher.ENCRYPT_MODE, key, zeroIv);
                byte[] encryptedData = cipher.doFinal(encryptString.getBytes());
                return Base64.encode(encryptedData);
        }
        public static String decryptDES(String decryptString, String decryptKey) throws Exception {
                byte[] byteMi = new Base64().decode(decryptString);
                IvParameterSpec zeroIv = new IvParameterSpec(iv);
//                IvParameterSpec zeroIv = new IvParameterSpec(new byte[8]);
                SecretKeySpec key = new SecretKeySpec(decryptKey.getBytes(), "DES");
                Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
                cipher.init(Cipher.DECRYPT_MODE, key, zeroIv);
                byte decryptedData[] = cipher.doFinal(byteMi);
                return new String(decryptedData);
        }
}
